package com.roger.myHome.controller;

import com.roger.myHome.aspect.WebLog;
import com.roger.myHome.entity.qto.TotalExpenseQry;
import com.roger.myHome.page.EUDataGridResult;
import com.roger.myHome.service.TotalExpenseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/totalExpense")
@Slf4j
public class TotalExpenseController {

    @Resource
    private TotalExpenseService totalExpenseService;

    @RequestMapping("/page")
    @ResponseBody
    @WebLog
    public EUDataGridResult page(@RequestParam(value="page",required=false) String page,
                                 @RequestParam(value="rows",required=false) String rows, HttpServletRequest req){

        TotalExpenseQry qryReq = new TotalExpenseQry();
        qryReq.setPage((Integer.parseInt(page) - 1) * Integer.parseInt(rows));
        qryReq.setRows(Integer.parseInt(rows));

        String ymd1 = req.getParameter("ymd1");
        String ymd2 = req.getParameter("ymd2");

        if (ymd1 != null && !"".equals(ymd1)) {
            ymd1 = ymd1.replace("-", "");
            qryReq.setYmdi1(Integer.valueOf(ymd1));
        }
        if (ymd2 != null && !"".equals(ymd2)) {
            ymd2 = ymd2.replace("-", "");
            qryReq.setYmdi2(Integer.valueOf(ymd2));
        }
        return totalExpenseService.page(qryReq);
    }
}
